package com.menggudf.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.menggudf.model.PartsCoordinateModel;
import com.menggudf.model.ResultModel;
import com.menggudf.model.SystemAdminModel;
import com.menggudf.service.PartsCoordinateService;

/**
 * 图片部位数据交互
 * 管理图片对应的坐标
 * */
@Controller
@RequestMapping("partInteraction")
public class PartDataInteractionController {
    
    @Autowired
    private PartsCoordinateService partsCoordinateService; 

    @RequestMapping("saveCoordinate")
    @ResponseBody
    public ResultModel saveCoordinate(
            @RequestParam(value="part") String part,
            @RequestParam(value="sexflag") String sexflag,
            @RequestParam(value="prosAndCons") String prosAndCons,
            @RequestParam(value="coordinate_X") String coordinate_X,
            @RequestParam(value="coordinate_Y") String coordinate_Y){
        return partsCoordinateService.saveCoordinate(part,sexflag,prosAndCons,coordinate_X,coordinate_Y);
        
    }
    
    @RequestMapping("/getAllCoordinate")
    @ResponseBody
    public List<PartsCoordinateModel> getAllCoordinate(
            @RequestParam(value="sexflag") String sexflag,
            @RequestParam(value="prosAndCons") String prosAndCons){
        
        return partsCoordinateService.getAllCoordinate(sexflag,prosAndCons);
        
    }
    
    @RequestMapping("deletePoint")
    @ResponseBody
    public ResultModel deletePoint(
            @RequestParam(value="sexflag") String sexflag,
            @RequestParam(value="prosAndCons") String prosAndCons,
            @RequestParam(value="coordinate_X") String coordinate_X,
            @RequestParam(value="coordinate_Y") String coordinate_Y,
            HttpSession httpSession){
        SystemAdminModel model = (SystemAdminModel) httpSession.getAttribute("SystemAdminModel");
        if(model==null || model.getFlag()!=1){
            return ResultModel.fail();
        }else{
            return partsCoordinateService.deletePoint(coordinate_X,coordinate_Y,sexflag,prosAndCons);
        }
    }
}
